package com.ruoyi.web.controller.car;

import com.ruoyi.car.domain.CarManage;
import com.ruoyi.car.service.ICarManageService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 车辆管理
Controller
 * 
 * @author ruoyi
 * @date 2020-07-01
 */
@Controller
@RequestMapping("/ruoyi/manage")
public class CarManageController extends BaseController
{
    private String prefix = "ruoyi/manage";

    @Autowired
    private ICarManageService carManageService;

    @RequiresPermissions("ruoyi:manage:view")
    @GetMapping()
    public String manage()
    {
        return prefix + "/manage";
    }

    /**
     * 查询车辆管理
列表
     */
    @RequiresPermissions("ruoyi:manage:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CarManage carManage)
    {
        startPage();
        List<CarManage> list = carManageService.selectCarManageList(carManage);
        return getDataTable(list);
    }

    /**
     * 查询车辆管理
     列表
     */
    @RequiresPermissions("ruoyi:manage:list")
    @PostMapping("/lists")
    @ResponseBody
    public List<CarManage> lists(CarManage carManage)
    {
        List<CarManage> list = carManageService.selectCarManageList(carManage);
        return list;
    }

    /**
     * 导出车辆管理
列表
     */
    @RequiresPermissions("ruoyi:manage:export")
    @Log(title = "车辆管理 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CarManage carManage)
    {
        List<CarManage> list = carManageService.selectCarManageList(carManage);
        ExcelUtil<CarManage> util = new ExcelUtil<CarManage>(CarManage.class);
        return util.exportExcel(list, "车辆管理");
    }

    /**
     * 新增车辆管理

     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存车辆管理

     */
    @RequiresPermissions("ruoyi:manage:add")
    @Log(title = "车辆管理 ", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CarManage carManage)
    {
        return toAjax(carManageService.insertCarManage(carManage));
    }

    /**
     * 修改车辆管理

     */
    @GetMapping("/edit/{cId}")
    public String edit(@PathVariable("cId") Integer cId, ModelMap mmap)
    {
        CarManage carManage = carManageService.selectCarManageById(cId);
        mmap.put("carManage", carManage);
        return prefix + "/edit";
    }

    /**
     * 修改保存车辆管理

     */
    @RequiresPermissions("ruoyi:manage:edit")
    @Log(title = "车辆管理 ", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CarManage carManage)
    {
        return toAjax(carManageService.updateCarManage(carManage));
    }

    /**
     * 删除车辆管理

     */
    @RequiresPermissions("ruoyi:manage:remove")
    @Log(title = "车辆管理 ", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(carManageService.deleteCarManageByIds(ids));
    }
}
